/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.psdk.util;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.os.Environment;
import android.provider.Settings.Secure;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Base64;
import com.qihoo.psdk.n;
import java.io.File;
import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class a {
    private static String a = "";
    private static String b = "";
    private static char[] c = null;

    public static String a(Context paramContext) {
        String str = "";
        if (paramContext != null) {
            TelephonyManager localTelephonyManager = (TelephonyManager) paramContext.getSystemService("phone");
            str = localTelephonyManager.getDeviceId();
            if (str == null)
                str = "";
        }
        return str;
    }

    public static String b(Context paramContext) {
        String str = "";
        if (paramContext != null) {
            TelephonyManager localTelephonyManager = (TelephonyManager) paramContext.getSystemService("phone");
            str = localTelephonyManager.getSimSerialNumber();
            if (str == null)
                str = "";
        }
        return str;
    }

    public static String c(Context paramContext) {
        String str = "";
        if (paramContext != null)
            str = paramContext.getPackageName();
        return str;
    }

    public static String a() {
        String str = Build.MODEL;
        if (str == null)
            str = "";
        str = str.replace(" ", "").replace(",", "");
        return str;
    }

    public static String b() {
        String str = "";
        try {
            str = Build.VERSION.RELEASE;
            if (str == null)
                str = "";
        } catch (Exception localException) {
            h.a("QDefine", localException);
        }
        return str;
    }

    public static String d(Context paramContext) {
        String str = "";
        try {
            str = Settings.Secure.getString(paramContext.getContentResolver(), "android_id");
        } catch (Exception localException) {
            h.a("QDefine", localException);
        }
        return str;
    }

    public static String a(String paramString) {
        String str = "";
        if (!(TextUtils.isEmpty(paramString))) {
            char[] arrayOfChar1 = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
            try {
                byte[] arrayOfByte1 = paramString.getBytes();
                MessageDigest localMessageDigest = MessageDigest.getInstance("MD5");
                localMessageDigest.update(arrayOfByte1);
                byte[] arrayOfByte2 = localMessageDigest.digest();
                int i = arrayOfByte2.length;
                char[] arrayOfChar2 = new char[i * 2];
                int j = 0;
                for (int k = 0; k < i; ++k) {
                    int l = arrayOfByte2[k];
                    arrayOfChar2[(j++)] = arrayOfChar1[(l >>> 4 & 0xF)];
                    arrayOfChar2[(j++)] = arrayOfChar1[(l & 0xF)];
                }
                str = new String(arrayOfChar2);
            } catch (Exception localException) {
                h.a("QDefine", localException);
            }
        }
        h.a("QDefine", "md5  input: " + paramString);
        h.a("QDefine", "md5 output: " + str);
        return str;
    }

    public static String c() {
        String str1 = "";
        int i = new Random().nextInt();
        if ((i <= 0) || (i > 1000))
            i = 1000;
        long l1 = System.currentTimeMillis() * i;
        long l2 = new Random().nextLong();
        if (l2 < 0L)
            l2 = -l2;
        String str2 = "000000" + Long.toHexString(l2);
        if (str2.length() > 7)
            str2 = str2.substring(str2.length() - 7);
        str1 = Long.toHexString(l1) + str2;
        if (str1.length() > 18)
            str1 = str1.substring(str1.length() - 18);
        str1 = str1.toUpperCase();
        return str1;
    }

    public static String d() {
        String str = "";
        try {
            str = Environment.getExternalStorageDirectory().getPath() + "/appcache/";
            File localFile = new File(str);
            if (!(localFile.exists()))
                localFile.mkdirs();
        } catch (Exception localException) {
            h.a("QDefine", localException);
        } catch (Error localError) {
            h.a("QDefine", localError);
        }
        return str;
    }

    public static boolean e(Context paramContext) {
        ConnectivityManager localConnectivityManager = (ConnectivityManager) paramContext
                .getSystemService("connectivity");
        if ((localConnectivityManager != null) && (localConnectivityManager.getActiveNetworkInfo() != null))
            return localConnectivityManager.getActiveNetworkInfo().isAvailable();
        return false;
    }

    public static String f(Context paramContext) {
        String str = "";
        try {
            ConnectivityManager localConnectivityManager = (ConnectivityManager) paramContext
                    .getSystemService("connectivity");
            NetworkInfo localNetworkInfo = localConnectivityManager.getActiveNetworkInfo();
            if ((localNetworkInfo != null) && (localNetworkInfo.isAvailable()))
                str = localNetworkInfo.getExtraInfo();
        } catch (Exception localException) {
            h.a("QDefine", "ex: " + localException.toString());
        }
        return str;
    }

    public static boolean g(Context paramContext) {
        int i = 0;
        ConnectivityManager localConnectivityManager = (ConnectivityManager) paramContext
                .getSystemService("connectivity");
        NetworkInfo localNetworkInfo = localConnectivityManager.getActiveNetworkInfo();
        if ((localNetworkInfo != null) && ("WIFI".equalsIgnoreCase(localNetworkInfo.getTypeName())))
            i = 1;
        return i;
    }

    public static String h(Context paramContext) {
        String str = "";
        try {
            WifiManager localWifiManager = (WifiManager) paramContext.getSystemService("wifi");
            WifiInfo localWifiInfo = localWifiManager.getConnectionInfo();
            str = localWifiInfo.getSSID();
            if (str == null)
                str = "";
        } catch (Exception localException) {
            h.a("QDefine", "ex: " + localException.toString());
        }
        return str;
    }

    public static String a(Context paramContext, String paramString) {
        String str = "";
        try {
            PackageManager localPackageManager = paramContext.getPackageManager();
            ApplicationInfo localApplicationInfo = localPackageManager.getApplicationInfo(
                    paramContext.getPackageName(), 128);
            if (localApplicationInfo != null)
                try {
                    str = localApplicationInfo.metaData.get(paramString).toString();
                } catch (Exception localException2) {
                    h.a("QDefine", localException2);
                }
        } catch (Exception localException1) {
            h.a("QDefine", localException1);
        }
        h.a("QDefine", "meta " + paramString + ": " + str);
        return str;
    }

    public static String e() {
        String str = "";
        try {
            str = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date());
        } catch (Exception localException) {
            h.a("QDefine", localException);
        } catch (Error localError) {
            h.a("QDefine", localError);
        }
        return str;
    }

    public static String f() {
        String str = "";
        Date localDate = new Date();
        int i = localDate.getYear() + 1900;
        int j = localDate.getMonth() + 1;
        int k = localDate.getDate();
        int l = localDate.getHours();
        int i1 = localDate.getMinutes();
        int i2 = localDate.getSeconds();
        str = str + i;
        if (j < 10)
            str = str + "0" + j;
        else
            str = str + j;
        if (k < 10)
            str = str + "0" + k;
        else
            str = str + k;
        if (l < 10)
            str = str + "0" + l;
        else
            str = str + l;
        if (i1 < 10)
            str = str + "0" + i1;
        else
            str = str + i1;
        if (i2 < 10)
            str = str + "0" + i2;
        else
            str = str + i2;
        return str;
    }

    public static String b(Context paramContext, String paramString)
  {
    String str1 = "";
    try
    {
      String str2 = Environment.getExternalStorageState();
      if ("mounted".equals(str2))
      {
        String str3 = Environment.getExternalStorageDirectory().getPath() + "/data/com/" + "qhpush" + "/regId/";
        File localFile = new File(str3);
        if (!(localFile.exists()))
          localFile.mkdirs();
        String str4 = str3 + paramContext.getPackageName();
        if (paramString != null)
        {
          n.a(str4, paramString);
          break label181:
        }
        str1 = n.b(str4);
        h.a("QDefine", "fileName: " + str4 + ", regId: " + str1);
        break label181:
      }
      h.a("QDefine", "SD card is oos");
    }
    catch (Exception localException)
    {
      h.a("QDefine", localException);
    }
    catch (Error localError)
    {
      h.a("QDefine", localError);
    }
    label181: return str1;
  }

    public static String a(Context paramContext, String paramString1, String paramString2) {
        try {
            if (TextUtils.isEmpty(a)) {
                a = b(paramContext, null);
                if (TextUtils.isEmpty(a)) {
                    a = i.b(paramContext, "registerId", "");
                    if (TextUtils.isEmpty(a)) {
                        String str1 = a(paramContext);
                        String str2 = b();
                        String str3 = a();
                        String str4 = b(paramContext);
                        String str5 = d(paramContext);
                        String str6 = a(paramContext, "QHOPENSDK_APPKEY");
                        String str7 = a(paramContext, "QHOPENSDK_CHANNEL");
                        h.a("QDefine", "*****************************");
                        h.a("QDefine", "packName: " + paramString2);
                        h.a("QDefine", "imei: " + str1);
                        h.a("QDefine", "osVersion: " + str2);
                        h.a("QDefine", "model: " + str3);
                        h.a("QDefine", "sn: " + str4);
                        h.a("QDefine", "androidId: " + str5);
                        h.a("QDefine", "appKey: " + str6);
                        h.a("QDefine", "channel: " + str7);
                        h.a("QDefine", "appId: " + paramString1);
                        a = a(paramString2 + str1 + str2 + str3 + str4 + str5 + str6 + paramString1 + c());
                        i.a(paramContext, "registerId", a);
                    }
                    b(paramContext, a);
                }
                else {
                    i.a(paramContext, "registerId", a);
                }
            }
        } catch (Exception localException) {
            h.a("QDefine", localException);
        } catch (Error localError) {
            h.a("QDefine", localError);
        }
        return a;
    }

    public static String g() {
        return a;
    }

    public static String i(Context paramContext) {
        try {
            b = a(paramContext, "QHOPENSDK_APPID");
        } catch (Exception localException) {
            h.a("QDefine", localException);
        } catch (Error localError) {
            h.a("QDefine", localError);
        }
        return b;
    }

    public static void b(Context paramContext, String paramString1, String paramString2) {
        Intent localIntent = new Intent();
        localIntent.setAction("com.qihoo.psdk.action.local");
        localIntent.setPackage(paramContext.getPackageName());
        localIntent.putExtra("targetPack", paramContext.getPackageName());
        localIntent.putExtra("type", paramString1);
        localIntent.putExtra("data", paramString2);
        paramContext.sendBroadcast(localIntent);
    }

    public static void a(Context paramContext, String paramString1, String paramString2, String paramString3,
            int paramInt) {
        Intent localIntent = new Intent();
        localIntent.setAction("com.qihoo.psdk.action.local");
        localIntent.setPackage(paramContext.getPackageName());
        localIntent.putExtra("targetPack", paramContext.getPackageName());
        localIntent.putExtra("type", paramString1);
        localIntent.putExtra("data", paramString2);
        localIntent.putExtra("appPackName", paramString3);
        localIntent.putExtra("appVersionCode", paramInt);
        paramContext.sendBroadcast(localIntent);
    }

    public static String b(String paramString) {
        if (c == null) {
            c = new char[b.length()];
            for (int i = 0; i < b.length(); ++i)
                c[i] = b.charAt(i);
        }
        byte[] arrayOfByte = Base64.decode(paramString, 11);
        for (int j = 0; j < arrayOfByte.length; ++j)
            arrayOfByte[j] = (byte) (arrayOfByte[j] ^ c[(j % c.length)]);
        return new String(arrayOfByte);
    }
}